package com.sixth.system.service.impl;/**
 * @author 633yh
 * @version 1.0
 */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sixth.core.entity.RegisteredItem;
import com.sixth.core.vo.R;
import com.sixth.system.mapper.RegisteredItemMapper;
import com.sixth.system.service.RegisteredItemService;
import com.sixth.system.vo.RegisteredItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Date;

/**
 * @author     ：Stu YH
 * @date       ：Created in 2024/8/20 20:22
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class RegisteredItemServiceImpl implements RegisteredItemService {
    @Autowired
    private RegisteredItemMapper registeredItemMapper;
    @Override
    public R<IPage<RegisteredItem>> selectByPage(RegisteredItemVo registeredItemVo) {
        Page<RegisteredItem> page = new Page<>(registeredItemVo.getPageNum(), registeredItemVo.getPageSize());
        QueryWrapper<RegisteredItem> wrapper = new QueryWrapper<>();
        if (registeredItemVo.getRegItemName()!=null){
            wrapper.like("reg_item_name",registeredItemVo.getRegItemName());
        }
        if (registeredItemVo.getStatus()!=null){
            wrapper.eq("status",registeredItemVo.getStatus());
        }
        Page<RegisteredItem> registeredItemPage = registeredItemMapper.selectPage(page, wrapper);
        return R.ok(registeredItemPage);

    }

    @Override
    public R addUpdate(RegisteredItem registeredItem) {
        registeredItem.setCreateTime(new java.util.Date());
        registeredItemMapper.insertOrUpdate(registeredItem);
        return R.ok();
    }

    @Override
    public R deletereg(Long[] registeredItemIds) {
        registeredItemMapper.deleteByIds(Arrays.asList(registeredItemIds));
        return R.ok();
    }
}